<?php
/**
 *author benald
 *客户介绍返利统计----分成系统
 *
 * @copyright  Copyright (c) 中国追溯
 * @since      File available since Release v1.1
 */

use Shopnc\Tpl;

defined('InShopNC') or exit('Access Invalid!');

class fencheng_rebateControl extends SystemControl
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 默认
     */
    public function indexOp()
    {
        $this->rebate_listOp();
    }

    /**
     * 活动列表
     */
    public function rebate_listOp()
    {
        Tpl::showpage('fencheng_rebate.list');
    }

    /**
     * 活动列表
     */
    public function rebate_list_xmlOp()
    {
        $condition = array();
        /*if ($_REQUEST['advanced']) {
            if (strlen($q = trim((string) $_REQUEST['kanjia_name']))) {
                $condition['kanjia_name'] = array('like', '%' . $q . '%');
            }
            if (strlen($q = trim((string) $_REQUEST['store_name']))) {
                $condition['store_name'] = array('like', '%' . $q . '%');
            }
            if ($_REQUEST['state'] != '') {
                $condition['state'] = intval($_REQUEST['state']);
            }

            $pdates = array();
            if (strlen($q = trim((string) $_REQUEST['pdate1'])) && ($q = strtotime($q . ' 00:00:00'))) {
                $pdates[] = "end_time >= {$q}";
            }
            if (strlen($q = trim((string) $_REQUEST['pdate2'])) && ($q = strtotime($q . ' 00:00:00'))) {
                $pdates[] = "start_time <= {$q}";
            }
            if ($pdates) {
                $condition['pdates'] = array(
                    'exp',
                    implode(' or ', $pdates),
                );
            }
        } else {
            if (strlen($q = trim($_REQUEST['query']))) {
                switch ($_REQUEST['qtype']) {
                    case 'kanjia_name':
                        $condition['kanjia_name'] = array('like', '%'.$q.'%');
                        break;
                    case 'store_name':
                        $condition['store_name'] = array('like', '%'.$q.'%');
                        break;
                }
            }
        }*/

        $model_hunter_apply = Model('hunter_apply');
        $hunter_apply_list  = (array)$model_hunter_apply->getList($condition, $_REQUEST['rp']);
        /*获取状态*/
        $state_array = $model_hunter_apply->getStateArray();

        $data              = array();
        $data['now_page']  = $model_hunter_apply->shownowpage();
        $data['total_num'] = $model_hunter_apply->gettotalnum();

        foreach ($hunter_apply_list as $val) {
            $o = '<a class="btn orange" href="' . urlAdminShop('', 'fencheng_rebate_detail', array(
                    'hunter_id' => $val['hunter_id'],
                )) . '"><i class="fa fa-check-circle"></i>审核</a>';

            $o .= '<a class="btn green" href="' . urlAdminShop('fencheng_rebate', 'rebate_del', array(
                    'kanjia_id' => $val['kanjia_id'],
                )) . '"><i class="fa fa-list-alt"></i>查看</a>';

            $o .= '</ul></span>';

            $i                               = array();
            $i['operation']                  = $o;
            $i['hunter_name']                = $val['hunter_name'] . '/' . $val['hunter_nikename'];
            $i['phone']                      = $val['phone'];
            $i['num']                        = $val['phone'];/*对象数量*/
            $i['total']                      = $val['total'];
            $i['withdraw']                   = $val['withdraw'];
            $i['freeze_money']               = $val['freeze_money'];
            $i['state']                      = $val['state'];/*状态*/
            $i['time']                       = date('Y-m-d H:i', $val['add_time']) . '/' . date('Y-m-d H:i', $val['login_last_time']);
            $data['list'][$val['hunter_id']] = $i;
        }

        echo Tpl::flexigridXML($data);
        exit;
    }

    /**
     * 活动规则
     */
     public function rebate_doingOp(){

         //新建处理
         if ($_POST['form_submit'] != 'ok') {
             /*编辑*/
             $model_doc  = Model('document');
             $doc    = $model_doc->getOneById(9);
             Tpl::output('doc',$doc);
             Tpl::showpage('fencheng_rebate_doing.edit');
             exit;
         }

         $param  = array();
         $param['doc_id']    = 9;
         $param['doc_content']= trim($_POST['doc_content']);
         $param['doc_time']  = time();
         $model_doc  = Model('document');
         $result = $model_doc->updates($param);
         if ($result){
             $this->log('编辑会员协议[ID:9]');
             showMessage('保存成功');
         }else {
             showMessage('保存失败');
         }

     }
}

    